package com.flying.oop.classmember.method;

/**
 * @ClassName: MethodDemo4
 * @createDate: 2023/6/21 7:54
 * @author: liu
 * @description: 可变参数
 *
 */
public class MethodDemo5 {
    public static void main(String[] args) {

        System.out.println(add(2, 5));


        System.out.println(add(new int[]{1, 2, 3, 4, 5, 6}));

        System.out.println(add(new int[]{45,3,5,6,24,34}));
        System.out.println(add(1, 4));
    }

    public static int add(int i,int j){
        return i+j;
    }


/*    public static int add(int[] nums){
        int sum=0;
        for (int num : nums) {
            sum+=num;
        }
        return sum;
    }*/

    //  可变参数  参数类型...参数名
    public static int add(int...nums){
        int sum=0;
        for (int num : nums) {
            sum+=num;
        }
        return sum;
    }

}
